import org.apache.spark.{SparkConf, SparkContext}

object home0331 {
  def main(args: Array[String]): Unit = {
    val peopleList = List(("男","男2"),("男","男2"),("男","男3"),("女","女1"),("女","女2"),("女","女3"))
    val conf = new SparkConf().setMaster("local").setAppName("home0331")
    val sc = new SparkContext(conf)
    val rdd = sc.parallelize(peopleList, 2)
    val result = rdd.combineByKey(
      (x:String)=>(List(x),1),
      (peo:(List[String], Int), x:String) => (x :: peo._1, peo._2 + 1),
      (sex1: (List[String], Int), sex2:(List[String], Int))
      => (sex1._1 ::: sex2._1,sex1._2 + sex2._2)
    )
    result.foreach(println)
  }
}
